import threading
import contextvars

local_data = threading.local()
local_data.session_id = 'session_id'
local_data.message_id = 'message_id'

context_data = contextvars.ContextVar('conversation_data', default=None)
context_data.set({"session_id": "session_id", "message_id": "message_id"})


def get_session_id():
    session_id = ""
    try:
        message = context_data.get()
        if message:
            session_id = message.get("session_id", "")
    except Exception:
        pass
    return session_id
